package com.chen.springboot.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.chen.springboot.entity.Order;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author Chen
 * @Date 2024/12/17 17:14
 */
@Data
public class OrderDto {
    @ExcelProperty(value = "商品名称", index = 0)
    private String orderName;
    @ExcelProperty(value = "订单编号", index = 1)
    private String orderNo;
    @ExcelProperty(value = "总价￥", index = 2)
    private BigDecimal payPrice;
    @ExcelProperty(value = "邮费￥", index = 3)
    private BigDecimal postFee;
    @ExcelProperty(value = "创建时间", index = 4)
    private Date createTime;
    @ExcelProperty(value = "支付时间", index = 5)
    private Date paymentTime;
    // 原始的 state 字段，将被忽略
    @ExcelIgnore
    private Integer state;
    @ExcelProperty(value = "支付状态", index = 6)
    private String stateString;
    @ExcelProperty(value = "购买人", index = 7)
    private String username;

    public OrderDto(Order order) {
        this.orderName = order.getOrderName();
        this.orderNo = order.getOrderNo();
        this.payPrice = order.getPayPrice();
        this.postFee = order.getPostFee();
        this.createTime = order.getCreateTime();
        this.paymentTime = order.getPaymentTime();
        this.state = order.getState();
        this.username = order.getUsername();
    }

    // 1-已支付，2-未支付，3-已取消，4-已发货，5-已完成，6-退款中
    public String getStateString() {
        if (state == null) {
            return "";
        }
        switch (state) {
            case 1:
                return "已支付";
            case 2:
                return "未支付";
            case 3:
                return "已取消";
            case 4:
                return "已发货";
            case 5:
                return "已完成";
            case 6:
                return "退款中";
            default:
                return "未知类型";
        }
    }

    public void setStateString(Integer state) {
        this.state = state;
        this.stateString = getStateString();
    }
}
